import Cookies from 'js-cookie'

const TokenKey = 'gdpykj'
const InfoSession = "gdpykj_session"
const SaveLoginInfo = "gdpykj_session_usr"
export function saveInfo(data) {
  let {
    id,
    avatar,
    username,
    token
  } = data;

  return Cookies.set(InfoSession, window.btoa(window.encodeURIComponent(id + "," + avatar + "," + username + "," + token)));
}

export function removeInfo() {
  return Cookies.remove(InfoSession);
}

export function getInfo() {
  return Cookies.get(InfoSession);
}

export function getToken() {
  return Cookies.get(TokenKey)
}

export function setToken(token) {
  return Cookies.set(TokenKey, token)
}


export function getId() {
  return Cookies.get('id')
}

export function setId(id) {
  return Cookies.set('id', id)
}

export function removeId() {
  return Cookies.remove('id')
}

export function removeToken() {
  return Cookies.remove(TokenKey)
}

export function saveLoginInfo(data) {
  let {
    username,
    password
  } = data;
  return Cookies.set(SaveLoginInfo, window.btoa(window.encodeURIComponent(username + "," + password)));
}

export function dontSaveLogin() {
  return Cookies.remove(SaveLoginInfo)
}

export function getSaveLogin() {
  return Cookies.get(SaveLoginInfo);
}

export function getSession() {
  return Cookies.get(InfoSession);
}